<template>
	<view>
		<uni-forms ref="form" :model="user" :rules="{}">
			<uni-forms-item name="telephone">
				<uni-easyinput v-model="user.telephone" placeholder="请输入用户名" />
			</uni-forms-item>

			<uni-forms-item name="password">
				<uni-easyinput v-model="user.password" type="password" placeholder="请输入密码" />
			</uni-forms-item>

		</uni-forms>
		<button @click="login" type="primary">登录</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user: {
					telephone: '666',
					password: '666'
				},
			}
		},
		methods: {
			login() {
				uni.request({
					url: 'http://localhost:8080/foodapp/user/login',
					method: 'post',
					data: this.user,
					success: res => {
						// console.log(res);
						if (res.data.success === true) {
							uni.showToast({
								title: res.data.data.username,
								icon: "success"
							});
							// 保存用户信息到本地存储：
							uni.setStorageSync('userinfo', res.data.data)
							// 切换到 个人中心页面：
							uni.navigateTo({
								url: '../my/my'
							})

						} else {
							uni.showToast({
								title: '用户名或密码错误',
								icon: 'error'
							});
						}
					},
				})
			}
		}
	}
</script>

<style>

</style>